<?php
namespace app\admin\controller;

use app\common\model\PersonalConfig as PersonalConfigModel;
use app\common\model\Opinion as OpinionModel;
use app\common\controller\AdminBase;
use think\Config;
use think\Db;

/**
 * 个人中心配置模块
 * Class PersonalConfig
 * @package app\admin\controller
 */
class PersonalConfig extends AdminBase
{
    protected $perconfig_model;
    protected $opinion_model;

    protected function _initialize()
    {
       parent::_initialize();
        $this->perconfig_model = new PersonalConfigModel();
        $this->opinion_model = new OpinionModel();
    }

    /**
     *  个人中心配置
     * @return mixed
     */
    public function index()
    {   $id=1;
       $config = $this->perconfig_model->find($id);

        return $this->fetch('index', ['config' => $config]);
    }


    /**
     * 反馈问题管理
     * @param string $keyword
     * @param int    $page
     * @return mixed
     */
    public function lists($keyword = '', $page = 1)
    {
       $where = [];
        if ($keyword) {
                
            $where['content'] = ['like', "%{$keyword}%"];
        }
        $list = $this->opinion_model->order('id desc')->paginate(15, false, ['page' => $page]);
        
        // print_r($list);exit;
        return $this->fetch('lists', ['list' => $list, 'keyword' => $keyword]);
    }

    /**
     * 反馈详情页面
     * @param $id
     * @return mixed
     */
    public function detail($id)
    {
        $detail = $this->opinion_model->find($id);
        // var_dump($video);exit;
        return $this->fetch('detail', ['detail' => $detail]);
    }

    
    /**
     * 更新修改配置
     * @param $id
     */
    public function update()
    {
        if ($this->request->isPost()) {
            $id=1;
            $data            = $this->request->post();
            // var_dump($data);exit;
            $forum                = $this->perconfig_model->find($id);
            $forum->id            = $id;
            $forum->version_num   = $data['version_num'];
            $forum->version_des   = $data['version_des'];
            $forum->content       = $data['content'];
            $forum->update_time   = time();
            // var_dump($video);exit;
            if ($forum->save() !== false) {
                $action = "个人中心配置";
                $this->getLog("3",$action);
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
            
        }
    }


    /**
     * 删除用户
     * @param $id
     */
    public function delete($id)
    {
        if ($this->opinion_model->destroy($id)) {
            $action = "个人中心用户ID".$_REQUEST['id'];
            $this->getLog("2",$action);
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }
}